package com.hiss.basic.starter.security.service;

import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.hiss.basic.starter.security.helper.SecurityHelper;
import com.hiss.basic.starter.security.model.AuthenticationModel;

import java.util.ArrayList;
import java.util.List;

public class StpPermissionImpl implements StpInterface {

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        AuthenticationModel authenticationModel = SecurityHelper.getAuthentication();
        if (ObjectUtil.isNotNull(authenticationModel)) {
            return new ArrayList<>(authenticationModel.getCodes());
        }
        return ListUtil.toList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        AuthenticationModel authenticationModel = SecurityHelper.getAuthentication();
        if (ObjectUtil.isNotNull(authenticationModel)) {
            return new ArrayList<>(authenticationModel.getRoles());
        }
        return ListUtil.toList();
    }
}
